import 'package:fig/models/media.dart';
import 'package:fig/views/video/video_player.dart';
import 'package:flutter/material.dart';

class MediaItem extends StatelessWidget {
  final Media media;
  final int crossAxisCount;

  MediaItem(this.media, {Key key, this.crossAxisCount = 3}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    const double radius = 8.0;
    final Size screenSize = MediaQuery.of(context).size;

    return GridTile(
      child: InkResponse(
        // enableFeedback: true,
        child: Flex(
          direction: Axis.vertical,
          children: [
            Expanded(flex: 1, child: ClipRRect(borderRadius: BorderRadius.circular(radius), child: Image.network(media.cover, fit: BoxFit.cover, width: screenSize.width / crossAxisCount))),
            Padding(padding: EdgeInsets.only(top: 6), child: Text(media.name, maxLines: 1, style: TextStyle(fontSize: 13))),
          ],
        ),
        onTap: () {
          // 返回后销毁
          Navigator.push(context, new MaterialPageRoute(maintainState: false, builder: (context) => VideoPlayerWidget(media: media)));
          print('点击了--->${media.name}');
        },
      ),

      // ClipRRect(borderRadius: BorderRadius.circular(radius), child: Image.network(media.cover, fit: BoxFit.cover)),
      // // 效果不怎么好
      // footer: Material(
      //   color: Colors.transparent,
      //   shape: const RoundedRectangleBorder(
      //     borderRadius: BorderRadius.vertical(bottom: Radius.circular(radius)),
      //   ),
      //   clipBehavior: Clip.antiAlias,
      //   child: GridTileBar(
      //     backgroundColor: Colors.black45,
      //     title: Text(media.name),
      //     subtitle: Text(media.description),
      //   ),
      // ),
    );
  }
}
